#!/bin/bash

set -e # exit on error
set -x # echo commands

if  [[ ! -z "${TRAVIS_TAG}" ]]; then
    echo
    echo "SKIPPING BUILD STAGE SCRIPT --- This is a build for release tag ${TRAVIS_TAG}"
    echo
    exit 0
fi

# build BokehJS
pushd bokehjs
node make build
popd

# build a noarch conda package for Bokeh using the just-built BokehJS
conda build conda.recipe --quiet --no-test --no-anaconda-upload --no-verify

# if this is an external contributor then the uploads below will fail
if [[ -z "${AWS_ACCESS_KEY_ID}" ]]; then
    echo
    echo "SKIPPING BUILD ASSET UPLOAD --- external committer"
    echo
    exit 0
fi

cd ${HOME}

# upload the noarch directory for later jobs in this build
tar czf conda-bld-noarch.tgz "miniconda/conda-bld/noarch"
artifacts upload                               \
    --bucket "ci.bokeh.org"                    \
    --target-paths "travis/${TRAVIS_BUILD_ID}/build" \
    conda-bld-noarch.tgz

# upload the BokehJS build directory for later jobs in this build
tar czf bokehjs-build.tgz "build/bokeh/bokeh/bokehjs/build"
artifacts upload                               \
    --bucket "ci.bokeh.org"                    \
    --target-paths "travis/${TRAVIS_BUILD_ID}/build" \
    bokehjs-build.tgz
